Repository navigation
feat(rust): add cargo meta command line and client and commands generators - #611
Merged
Merged
Conversation
…mands generators Phase 2 of the Rust port (preview, ADR-0065 Amendment 1): a Rust developer can run the whole codegen loop on a JSON or YAML model. Run engine and CLI - gen removes a generated file nothing emits any more (an edited one is refused by name) and prints a change report with the crates to re-check. - cargo meta init scaffolds the config, the ignore rules and a first metadata file, writing only what is missing. - cargo meta verify --codegen renders in memory, compares with disk and exits 1 on drift; --db, --templates and --deps exit 2 with the reason. - cargo meta eject writes a codegen/ crate the project owns; gen and verify then build and run it. --undo takes back copies still identical. - Exit codes follow the shared contract: 0, 1, 2. Generators - entity: <Name>Create and <Name>Patch bodies, validate(), exact decimals and signed durations in a generated meta_support crate, wire.nullMembers. - client (new): a typed reqwest client per served entity, derived from the REST contract, with typed filters and sorts. - commands (new, Rust-only by decision): clap command groups over the client, as a library with no main. Gates - validation-conformance through the generated validate(), the decimal and duration wire vectors, the core writer corpus, both columns of the skip corpus, and the generator registry with the eject contract. - A compile gate builds and format-checks every generator's output and drives the generated client and commands over HTTP, from a committed lockfile. A scale gate holds twenty copies of the fitness model to linear growth and a size budget. The generator registry records client and commands with rust as their only port. Schema migrations and database checks stay with the Node meta tool. Nothing is published.
…egen crates Behaviour-preserving cleanup from the pre-gate simplification pass: no generated output changes (goldens, compile gate and scale gate unchanged).
# Conflicts: # README.md # docs/CONFORMANCE.md # docs/ports/rust.md # spec/decisions/README.md
… crate into the skip key A project's owned codegen crate that fails to build, or a generator in it that panics, made cargo meta gen and verify exit 101; the documented codes are 0, 1 and 2, so anything else the owned crate answers is now a failed run, 1. The skip key named three parts of the owned crate. The generator list is the project's file and may pull in any module beside it, so an edit there left gen reporting a skip and verify answering in sync over stale output. Every file under codegen/ is now an input, except its build directory and lockfile. Also brings the merged business-rules test and docs in line with this branch: rules_inert.rs covers all three shipped generators, and the two pages that said Rust has no verify now say it has the codegen gate only.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What Changed
cargo metacommand (metaobjects-clicrate,cargo-metabinary, unpublished).initscaffolds.metaobjects/config.json, ignore rules and a first metadata file.genremoves generated files nothing emits any more (hand-edited ones are refused by name) and reports created, updated and removed files.verify --codegenrenders in memory and exits 1 on drift.--db,--templatesand--depsexit 2 and say where those checks live.eject <generator>writes an ownedcodegen/crate thatgenandverifythen build and run.eject --undoremoves only copies still identical to the shipped source.entitygenerator now also emits<Name>Create,<Name>Patchandvalidate(), with exact decimals and durations in a generatedmeta_supportcrate, and honorswire.nullMembers. Newclientgenerator: a typedreqwestclient per served entity with a query type checked at compile time. Newcommandsgenerator:clapcommand groups over that client, emitted as a library.commandsis Rust-only, recorded infixtures/generator-registry-conformance/registry.jsonand ADR-0065 Amendment 1.validation-conformance, the decimal and duration wire vectors, writer conformance, the skip-corpus cases for Rust, a compile gate that builds and formats generated output and drives the client over HTTP against a local stub, and a scale gate. Documents the command indocs/ports/rust.md,docs/features/cli.mdandCHANGELOG.md. Rust stays preview;metaobjects-cliand the codegen crate arepublish = false.Gate runs
This PR took 2 no-mistakes runs. The first was started on a clean pre-run check and aborted about five minutes in, at its first review round and before anything was pushed: the business-rules PR (#610) merged four minutes after the run had rebased, and it touches four of the same doc files, so that run could only have ended in a branch that did not merge.
mainwas merged in, the four files resolved keeping both sides' entries, the first run's two review findings (rows 19 and 20 below) fixed with tests, and the second run validated the result.The merge also needed two repairs the text merge did not flag: the business-rules PR's Rust test (
rules_inert.rs) did not compile against this branch's generator context and now covers all three shipped generators, and two of its doc sentences said Rust has noverify.Design forks decided in this PR
Each is recorded in ADR-0065 Amendment 1. The first three are the owner's rulings; the rest are calls the work forced.
commandsshared vocabulary?clientandcommandswithrustas the only port.ejectwrites acodegen/crate the project owns, andgen/verifybuild and run it.<pkg>(entity),<pkg>_client,<pkg>_cli. Shared code is generated too:meta_support,meta_client,meta_cli. Nothing imports MetaObjects.Decimal).wire.decimalsDecimal.wire.nullMembersis honored.String, withvalidate()checking the form.validator.regexvalidate()reports a distinct violation ("pattern could not be evaluated within limits"), never the ordinary no-match message.<Name>Createonly.verifysurfaceverifyis--codegen.--db,--templates,--depsexit 2 with where the check lives. Nofmtyet.fmt.@filterablefield and operator; an enum of@sortablefields;rawas the escape hatch.get/update/deleteonly for a single key of text or a whole number./{id}in the contract.commandsoutputclap::Subcommandand an asyncrun, nomain.commandsload_benchis record-only.stages.pyruns Rust with--generators entityby default.cargo meta gennow runs three generators; the row would otherwise stop being comparable with its own history.codegen/crate breakscodegen/, except its build directory andCargo.lock.ejectwrites left an edit elsewhere unseen. Found in review.Not in this PR
Rust migrations and database checks (roadmap phase 6; they stay with the Node
metatool), the sqlx/axum service tier, the prompt pillar,fmt, clients for projections and reports, publishing and version numbers.Validation
Risk Assessment
✅ Low: I reviewed only the two fix-round commits (matcher rewrite, exit-code mapping and owned-crate skip key) and found no defect, but I did not read the other ~70 changed files of this phase, so the pass is partial.
Testing
Ran three live scenarios against the built cargo-meta binary in disposable scratch projects: JSON and YAML model gen/verify with drift refusal; owned codegen/ crate skip-key coverage of an extra file beside main.rs; broken owned crate and usage exit codes. All pass with exit codes and CLI output captured to evidence files. Broad regression came from the configured test command
scripts/ci-local.sh --affected --strict-toolchainswith its passing outcome, not rerun here. Not driven: a generator panic (exit 101 mapping) and Rust migrations (out of scope). Overall result: pass.cargo meta gen --bogusexit=2Evidence: Scenario 1: JSON model init/gen/verify, drift detection and gen refusal (transcript)
Evidence: Scenario 2 and 3: owned codegen skip key, gen --list, broken crate exit 1, usage exit 2 (transcript)
Pipeline
Updates from git push no-mistakes
✅ **Intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
🔧 **Review** - 3 issues found → auto-fixed ✅
server/rust/metaobjects-codegen/src/emitted/pattern.rs:27- The matcher fails closed on depth, which turns a legitimate long input into a wrong validation verdict without any error. DEPTH_LIMIT is 1000 and each iteration of a repeated group (rep_more, thenseq, thennode) uses several levels. A valid value of a few hundred characters against a pattern such as^(\w+\s?)*$or^(a)*$hits the limit,full_matchreturns false, and the generatedvalidate()reports "'field' does not match required pattern".tests/pattern.rslong_inputs_do_not_overflow_the_stackpins!full_match("(a)*", 200_000 'a'), so the false negative is deliberate. A diagnosable result (a distinct violation message, or raising the limit with an explicit heap stack) or an iterative matcher would change behaviour, so the remedy needs an owner decision, not a mechanical fix. Sibling sites:src/emitted/pattern.rs:25(STEP_BUDGET gives up the same way),src/entity.rsmember_checks(emitscheck::pattern, which cannot tell "gave up" from "no match"),tests/pattern.rs(long_inputs_do_not_overflow_the_stack).server/rust/metaobjects-codegen/tests/generator_registry.rs:24-depth_an_owned_copy_names_nothing_outside_the_engine_surfaceproves the registry's engine modules are exported by greppingsrc/lib.rsfor lines equal topub mod <name>;(LIB_RSviainclude_str!). A commented-out or cfg-gated line would pass. This is a source-text proxy for "the crate exports this module". The behavioural proof already exists in the ejected-alone build inmetaobjects-cli/tests/cli.rs. Replace the grep with something executable, such as a generateduse metaobjects_codegen::<module>;probe, or drop the LIB_RS check and rely on the build test. The scan overr.source(the textejectcopies into a project) reads a persisted, shipped artifact, so it is a legitimate text contract.docs/ports/rust.md:186- The command examples do not match the model they describe.app order create --json '{"title":"A bike"}' --total 12.50andOrderQuery::new().title_like(...).total_gte(&"10.00".parse()?)use theshopOrder, which has notitlefield. In that modeltotalisfield.currency, so the generated flag isOption<i64>(minor units) and--total 12.50is rejected by clap. Thetotal_gteargument would be ani64, not&Decimal. A reader copying the example gets a compile or usage error. Use a field and value the shop golden actually has (for example--total 1250,statusorcreatedAt).🔧 Fix applied.
✅ Re-checked - no issues remain.
✅ **Test** - passed
✅ No issues found.
cargo meta gen --bogusexit=2scripts/ci-local.sh --affected --strict-toolchainsBuiltcargo build -p metaobjects-cli --bin cargo-meta(already up to date in server/rust/target)Put target/debug on PATH and rancargo meta init|gen|verifyvia cargo's external-subcommand dispatch on a JSON model in a scratch projectHand-edit of generated/shop/src/order.rs, thencargo meta verify(expect exit 1, drifted) andcargo meta gen(expect refusal, exit 1)YAML model (metaobjects/meta.shop.yaml)cargo meta gen(exit 0)cargo meta eject entity, then owned-cratecargo meta genbuilds codegen/ and runs it (exit 0), repeat gen skips with stored keyEdit codegen/extra.rs (a file beside main.rs, not a named input) thencargo meta genmust not skip; repeat skips againcargo meta gen --listshows commands generator asRust only, and entity markedowned: identicalBroken codegen/main.rs:cargo meta genandcargo meta verify --codegenexit 1 (not 101)cargo meta gen --bogusexits 2 with valid-flag listTranscripts kept locally (scenario1-json-gen-verify-drift.txt and scenario2-owned-codegen-skip-key-and-exit-codes.txt); the excerpts above are from themRemoved the scratch projects; no background processes started; worktree git status clean✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.